enum SystemType
{
    WINDOWS = 0,
    IPHONE,
    ANDROID,
    IPAD,
    LINUX,
    MAC,
    UCBROWER
}
enum ScreenOrientation
{
    LANDSCAPE = 0,
    PORTRAIT
}
module WindSpirit
{
    export class Util
    {
        static resizeTimer = null;
        static get stageW()
        {
            return egret.MainContext.instance.stage.stageWidth;
        }
        static get stageH()
        {
            return egret.MainContext.instance.stage.stageHeight;
        }
        static get centerX()
        {
            return this.stageW >> 1;
        }
        static get centerY()
        {
            return this.stageH >> 1;
        }
        static get clientW()
        {
            return document.documentElement.clientWidth;
        }
        static get clientH()
        {
            return document.documentElement.clientHeight;
        }
        static get scaleX()
        {
            var scaleX = this.stageW / WindSpirit.Const.DESIGN_WIDTH;
            return scaleX;
        }
        static get scaleY()
        {
            var scaleY = this.stageH / WindSpirit.Const.DESIGN_HEIGHT;
            return scaleY;
        }
        static printInfo()
        {
            var style = "background:#e44c25;color:#000000;border-right:100px solid #fc6;border-left:10px solid #000;";
            console.log("%cwww.windspirit.cn",style);
            console.log("%c" + window.location.href,style);
            console.log("%c egret engine v2.0.5",style);
        }
        static onResize()
        {
            var _this = this;
            var doResize = function()
            {
                egret.MainContext.instance.stage.changeSize();
                _this.resizeTimer = null;
            };
            window.onresize = function()
            {
                if(_this.resizeTimer == null)
                {
                    _this.resizeTimer = setTimeout(doResize,300);
                }
            };
        }
        static solution()
        {
            var scaleMode = egret.MainContext.deviceType == egret.MainContext.DEVICE_MOBILE ? egret.StageScaleMode.EXACT_FIT : egret.StageScaleMode.SHOW_ALL;
            egret.MainContext.instance.stage.scaleMode = scaleMode;
        }
        static showFPS()
        {
            egret.Profiler.getInstance().run();
        }
        static addChildren(parent: egret.DisplayObjectContainer,children: egret.DisplayObject[] = [])
        {
            var len = children.length;
            for(var a = 0;a < len;a++)
            {
                parent.addChild(children[a]);
            }
        }
        static onStageStateChange()
        {
            egret.MainContext.instance.stage.addEventListener(egret.Event.DEACTIVATE,() =>
            {
                console.log("game deactivate");
                if(System.curMusic)
                {
                    System.curMusic.pause();
                }
                egret.Ticker.getInstance().pause();
            },this);
            egret.MainContext.instance.stage.addEventListener(egret.Event.ACTIVATE,() =>
            {
                console.log("game activate");
                if(System.curMusic)
                {
                    System.curMusic.resume();
                }
                egret.Ticker.getInstance().resume();
            },this);
        }
        static isWeiXinBrowser()
        {
            var b = "" + window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i);
            if("null" == b)
            {
                return !1;
            }
            if("micromessenger" == b)
            {
                return !0;
            }
        }
        static getType()
        {
            var b = window.navigator.userAgent.toLowerCase();
            b.match(/MicroMessenger/i);
            if("windows nt" == "" + b.match(/windows nt/i))
                return SystemType.WINDOWS;
            if("iphone" == "" + b.match(/iphone/i))
                return SystemType.IPHONE;
            if("android" == "" + b.match(/android/i))
                return SystemType.ANDROID;
            if("ipad" == "" + b.match(/ipad/i))
                return SystemType.IPAD;
            if("linux" == "" + b.match(/linux/i))
                return SystemType.LINUX;
            if("mac" == "" + b.match(/mac/i))
                return SystemType.MAC;
            if("ucbrower" == "" + b.match(/ucbrower/i))
                return SystemType.UCBROWER;
        }
        static screenOrientation()
        {
            return 90 == Math.abs(window['orientation']) ? 0 : 1
        }
        static createBitmapByName(name: string): egret.Bitmap
        {
            var a = new egret.Bitmap(RES.getRes(name));
            return a;
        }
        static newMC(b,d,a,c,k,f = 0.5,g = 0.5,m = 0): egret.MovieClip
        {
            d = RES.getRes(d);
            a = RES.getRes(a);
            a = new egret.MovieClipDataFactory(d,a);
            b = new egret.MovieClip(a.generateMovieClipData(b));
            b.anchorX = f;
            b.anchorY = g;
            b.x = c;
            b.y = k;
            m && (b.frameRate = m);
            return b;
        }
        static newLine(b,d,a,c,k,f): egret.Shape
        {
            var g = new egret.Shape;
            g.graphics.lineStyle(f,k);
            g.graphics.moveTo(b,d);
            g.graphics.lineTo(a,c);
            return g;
        }
        static newRoundRect(b,d,a,c,k,f,g,m,h,l): egret.Sprite
        {
            var n = new egret.Sprite;
            n.graphics.lineStyle(g,m);
            n.graphics.beginFill(h,l);
            n.graphics.drawRoundRect(b,d,a,c,k,f);
            n.graphics.endFill();
            n.x = b;
            n.y = d;
            n.width = a;
            n.height = c;
            return n;
        }
        static newRect(b,d,a,c,k,f,g,m): egret.Sprite
        {
            var h = new egret.Sprite;
            h.graphics.lineStyle(g,m);
            h.graphics.beginFill(k,f);
            h.graphics.drawRect(b,d,a,c);
            h.graphics.endFill();
            h.width = a;
            h.height = c;
            return h;
        }
        static newCircle(b,d,a,c,k,f,g): egret.Sprite
        {
            var m = new egret.Sprite;
            m.graphics.lineStyle(f,g);
            m.graphics.beginFill(c,k);
            m.graphics.drawCircle(0,0,a);
            m.graphics.endFill();
            m.x = b;
            m.y = d;
            return m;
        }
        static newBMT(b,d,a,c,k = 0.5,f = 0.5): egret.BitmapText
        {
            var g = new egret.BitmapText;
            g.font = RES.getRes(b);
            g.x = d;
            g.y = a;
            g.scaleX = g.scaleY = c;
            g.anchorX = g.anchorY = 0.5;
            g.anchorX = k;
            g.anchorY = f;
            return g;
        }
        static newBM(b,d,a,c = 0.5,k = 0.5,f = null): egret.Bitmap
        {
            var g = new egret.Bitmap;
            g.texture = RES.getRes(b);
            g.anchorX = c;
            g.anchorY = k;
            g.x = d;
            g.y = a;
            f && (g.name = f);
            return g;
        }
        static getStrRear(b,d)
        {
            return b.substring(b.lastIndexOf(d) + 1);
        }
        static newTF(b, d, a, c, k, f = false, h = null, l = null)
        {
            var g = new egret.TextField;
            g.text = b;
            g.x = d;
            g.y = a;
            g.size = c;
            g.textColor = k;
            g.anchorX = g.anchorY = 0.5;
            h && (g.stroke = h, g.strokeColor = l);
            g.bold = f;
            g.textAlign = egret.HorizontalAlign.CENTER;
            g.fontFamily = "微软雅黑";
            return g;
        }
        static compare(b, d)
        {
            return 1 == b - d || -2 == b - d ? 1 : b == d ? 0 : -1;
        }
        static newBg(color:number = 0,alpha = 1):egret.Shape
        {
            var bg = new egret.Shape;
            bg.graphics.beginFill(color,alpha);
            bg.graphics.drawRect(0,0,WindSpirit.Util.stageW,WindSpirit.Util.stageH);
            return bg;
        }
    }
}